}
impl TargetKind {
- pub fn name(&self) -> &'static str {
+ /// Returns a vector of crate types as specified in a manifest with one difference.
+ /// For ExampleLib it returns "example" instead of crate types
+ pub fn kinds(&self) -> Vec<&str> {
use self::TargetKind::*;
match *self {
- Lib(_) => "lib",
- Bin => "bin",
- ExampleBin | ExampleLib(_) => "example",
- Test => "test",
- CustomBuild => "custom-build",
- Bench => "bench"
+ Lib(ref kinds) => kinds.iter().map(LibKind::crate_type).collect(),
+ Bin => vec!["bin"],
+ ExampleBin | ExampleLib(_) => vec!["example"],
+ Test => vec!["test"],
+ CustomBuild => vec!["custom-build"],
+ Bench => vec!["bench"]
}
}
+ /// Returns a vector of crate types as specified in a manifest
pub fn crate_types(&self) -> Vec<&str> {
use self::TargetKind::*;
match *self {
impl Encodable for Target {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
SerializedTarget {
- kind: vec![self.kind.name()],
+ kind: self.kind.kinds(),
crate_types: self.kind.crate_types(),
name: &self.name,
src_path: &self.src_path.display().to_string(),
}"#));
}
+#[test]
+fn library_with_several_crate_types() {
+ let p = project("foo")
+ .file("src/lib.rs", "")
+ .file("Cargo.toml", r#"
+[package]
+name = "foo"
+version = "0.5.0"
+
+[lib]
+crate-type = ["lib", "staticlib"]
+ "#);
+
+ assert_that(p.cargo_process("metadata"), execs().with_json(r#"
+ {
+ "packages": [
+ {
+ "name": "foo",
+ "version": "0.5.0",
+ "id": "foo[..]",
+ "source": null,
+ "dependencies": [],
+ "license": null,
+ "license_file": null,
+ "description": null,
+ "targets": [
+ {
+ "kind": [
+ "lib",
+ "staticlib"
+ ],
+ "crate_types": [
+ "lib",
+ "staticlib"
+ ],
+ "name": "foo",
+ "src_path": "[..][/]foo[/]src[/]lib.rs"
+ }
+ ],
+ "features": {},
+ "manifest_path": "[..]Cargo.toml"
+ }
+ ],
+ "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
+ "resolve": {
+ "nodes": [
+ {
+ "dependencies": [],
+ "id": "foo 0.5.0 (path+file:[..]foo)"
+ }
+ ],
+ "root": "foo 0.5.0 (path+file:[..]foo)"
+ },
+ "version": 1
+ }"#));
+}
#[test]
fn cargo_metadata_with_deps_and_version() {
}
#[test]
-fn carg_metadata_bad_version() {
+fn cargo_metadata_bad_version() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));